package com.itheima.tcp;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(10000);
        while (true) {
            Socket accept = socket.accept();
            InputStream is = accept.getInputStream();

            //String s = UUID.randomUUID().toString();
            long l = System.currentTimeMillis();
            FileOutputStream fos = new FileOutputStream("day16_网络编程\\"+l+".png");
            int i;
            byte[] bytes = new byte[1024];
            while((i = is.read(bytes))!=-1) {
                fos.write(bytes,0,i);
            }
            OutputStream os = accept.getOutputStream();
            os.write("上传成功".getBytes());
            fos.close();
            accept.close();
        }

    }
}
